package com.heima.controller;


import com.heima.common.PageResult;
import com.heima.pojo.dto.PageQueryDTO;
import com.heima.pojo.dto.RegionSaveDTO;
import com.heima.service.RegionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/vm-service/region")
public class RegionController {

    @Autowired
    private RegionService regionService;

    @GetMapping("/search")
    public PageResult queryRegion(PageQueryDTO page){
        log.info("区域搜索：{}",page);
        return regionService.queryRegion(page);
    }

    @PostMapping
    public Boolean save(@RequestBody RegionSaveDTO dto){
        log.info("新增区域：{}",dto);
        return regionService.save(dto);
    }

    @PutMapping("/{regionId}")
    public Boolean update(@PathVariable String regionId,@RequestBody RegionSaveDTO dto){
        log.info("修改区域：{}",regionId,dto);
        return regionService.update(regionId,dto);
    }

    @DeleteMapping("/{regionId}")
    public Boolean delete(@PathVariable String regionId){
        return regionService.delete(regionId);
    }
}
